package com.verisette.ncos.service.approver.bizunit;

import java.sql.Timestamp;
import java.util.Date;

import org.apache.log4j.Logger;
import org.corp.agi.common.exception.ProcessException;
import org.corp.agi.service.bean.ProcessContext;
import org.corp.agi.service.bizunit.CommonBusinessUnit;

import com.verisette.ncos.common.ProjectConstant;
import com.verisette.ncos.persistence.domain.MasterUserProfile;
import com.verisette.ncos.persistence.domain.TransCustomerOrder;

public class CardPrintBU extends CommonBusinessUnit{
	
	private Logger LOG = Logger.getLogger(CardPrintBU.class);

	@Override
	public void execute(ProcessContext p) throws ProcessException 
	{
		if(LOG.isDebugEnabled())
		{
			LOG.debug("Processing CardPrintBU...");
		}
//		UserBean user = p.getUserBean();
		MasterUserProfile user = (MasterUserProfile)p.getUserBean();
		
		TransCustomerOrder order = (TransCustomerOrder)p.getValueObject();
		
		TransCustomerOrder entity = (TransCustomerOrder) commonDAO.findById(
				TransCustomerOrder.class, order.getOrderId());
		
		Date d = new Date();
		entity.setStatus(ProjectConstant.STATUS_PRINT);
		entity.setExportedDate(new Timestamp(d.getTime()));
		entity.setUpdatedDate(new Timestamp(d.getTime()));
		entity.setExportedBy(user.getUsername());
		entity.setExportedUspId(user.getUspId());
		entity.setSentDate(order.getSentDate());
		
//		
//		Calendar sentDate = Calendar.getInstance();
//		sentDate.setTime(d);
//		
//		int amount = 2;
//		if(entity.getQuantity()>300){
//			amount = 3;
//		}
//		
//		sentDate.add(Calendar.DAY_OF_WEEK, amount);
//		entity.setSentDate(new Timestamp(sentDate.getTimeInMillis()));
		entity.setSentBy(user.getUsername());
		entity.setSentUspId(user.getUspId());
		
		order = (TransCustomerOrder)commonDAO.update(entity);
		p.setValueObject(order);
//		p.setValueObject(id);
	}

}
